<?php
namespace app\api\controller;

use think\Controller;
use think\Cache;
//use app\common\model\SmsModel as Sms;

class SmsController extends Controller{
	//初始化方法
	protected function initialize(){
	 	parent::initialize();
		header('Access-Control-Allow-Origin:*');
		header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, authKey, sessionId");
    }

	//国家区号
	public function smsCode(){
		$data	=	array(
            array('id'=>'82','name'=>'KOREA（REP OF）'),
            array('id'=>'84','name'=>'VIETNAM'),
			array('id'=>'91','name'=>'INDIA'),
			array('id'=>'60','name'=>'MALAYSIA'),
			array('id'=>'63','name'=>'PHILIPPINES'),
			array('id'=>'62','name'=>'INDOESIA'),
			array('id'=>'65','name'=>'SINGAPORE'),
			array('id'=>'852','name'=>'HONGKONG'),
			array('id'=>'853','name'=>'MACAU'),
		);
		return json($data);
	}

    /**
     * 发送短信验证码（POST形式）
     * @return [type] [description]
    */
    public function sendSMSCode(){
        $param = input('param.');

        $dest  = $param['dest'];// 手机号
        $phone = $param['phone'] ;// 手机号
        $code_type = $param['login_type'];
        if ($code_type=='phone'){
//                Log::write("xxxxx code:".$dest."-".$phone);
            $data = model('Sms')->sendSMSCode($dest,$phone);
        }else{
            $data = model("common/sms")->sendCode2Mail($phone);
        }
        return json($data);
    }


}
